<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: orders_edit_products.php 81 2013-09-21 12:02:49Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 81 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 12:02:49 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

if(isset($_GET['add']) && $_GET['add'] == 'special') {
	$sql_data_array = array('orders_id' => $_GET['oID'],
							'products_id' => '999999',
							'products_name' => 'Zusatzartikel',
							'products_model' => '11111',
							'products_ean' => '000000000000',
							'products_price' => '1.00',
							'products_discount_made' => '', 
							'final_price' => '1.00',
							'products_tax' => '19.0000',
							'products_quantity' => '1',
							'allow_tax' => '1');

	$db->db_perform(TABLE_ORDERS_PRODUCTS, $sql_data_array);
}

if(!$_GET['oID'])
	$_GET['oID'] = $_POST['oID'];

$order = new order($_GET['oID']);
?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
   <tr class="dataTableHeadingRow">
       <td class="dataTableHeadingContent"><b><?php echo TEXT_PRODUCT_ID;?></b></td>
       <td class="dataTableHeadingContent"><b><?php echo TEXT_QUANTITY;?></b></td>
       <td class="dataTableHeadingContent"><b><?php echo TEXT_PRODUCT;?></b></td>
       <td class="dataTableHeadingContent"><b><?php echo TEXT_PRODUCTS_MODEL;?></b></td>
       <td class="dataTableHeadingContent"><b><?php echo TEXT_TAX;?></b></td>
       <td class="dataTableHeadingContent"><b><?php echo TEXT_PRICE;?></b></td>
       <td class="dataTableHeadingContent"><b><?php echo TEXT_FINAL;?></b></td>
       <td class="dataTableHeadingContent">&nbsp;</td>
       <td class="dataTableHeadingContent">&nbsp;</td>
   </tr>
	<?php for ($i = 0, $n = sizeof($order->products); $i < $n; $i++) { ?>
		<tr class="dataTableRow">
			<?php
				echo draw_form('product_edit', FILENAME_ORDERS_EDIT, 'action=product_edit&'.getMenuID('orders_edit'), 'post');
				echo draw_hidden_field('oID', $_GET['oID']);
				echo draw_hidden_field('opID', $order->products[$i]['opid']);
			?>
			<td class="dataTableContent"><?php echo draw_input_field('products_id', $order->products[$i]['id'], 'size="5"');?></td>
			<td class="dataTableContent"><?php echo draw_input_field('products_quantity', $order->products[$i]['qty'], 'size="2"');?></td>
			<td class="dataTableContent"><?php echo draw_input_field('products_name', $order->products[$i]['name'], 'size="20"');?></td>
			<td class="dataTableContent"><?php echo draw_input_field('products_model', $order->products[$i]['model'], 'size="10"');?></td>
			<td class="dataTableContent"><?php echo draw_input_field('products_tax', $order->products[$i]['tax'], 'size="6"');?></td>
			<td class="dataTableContent"><?php echo draw_input_field('products_price', $order->products[$i]['price'], 'size="10"');?></td>
			<td class="dataTableContent"><?php echo $order->products[$i]['final_price'];?></td>
			<td class="dataTableContent">
				<?php
					echo draw_hidden_field('allow_tax', $order->products[$i]['allow_tax']);
					echo '<button type="submit" class="button" onclick="this.blur();">'.BUTTON_SAVE.'</button>';
					echo '</form>';
				?>
			</td>
			<td class="dataTableContent">
				<?php
					echo draw_form('product_delete', FILENAME_ORDERS_EDIT, 'action=product_delete&'.getMenuID('orders_edit'), 'post');
					echo draw_hidden_field('oID', $_GET['oID']);
					echo draw_hidden_field('opID', $order->products[$i]['opid']);
					echo '<button type="submit" class="button" onclick="this.blur();">'.BUTTON_DELETE.'</button>';
					echo '</form>';
				?>
			</td>
		</tr>
		<tr class="dataTableRow">
		<td class="dataTableContent" colspan="8">&nbsp;</td>
			<td class="dataTableContent">
			<?php
				echo draw_form('select_options', FILENAME_ORDERS_EDIT, '', 'GET');
				echo draw_hidden_field('menu', $_GET['menu']);
				echo draw_hidden_field('edit_action', 'options');
				echo draw_hidden_field('pID', $order->products[$i]['id']);
				echo draw_hidden_field('oID', $_GET['oID']);
				echo draw_hidden_field('opID', $order->products[$i]['opid']);
				echo '<button type="submit" class="button" onclick="this.blur();">'.BUTTON_PRODUCT_OPTIONS.'</button>';
				echo '</form>';
			?>
			</td>
		</tr>
	<?php } ?>
</table>
<br />
<div style="text-align:right">
	<button class="button" onclick="window.location.href='<?php echo href_link('orders_edit.php', getMenuID('orders_edit').'&add=special&edit_action=products&oID='.(int)$_GET['oID']) ?>'">
		Zusatzartikel einf&uuml;gen
	</button>
</div>
<br />

<table border="0" width="100%" cellspacing="0" cellpadding="2">
	<tr class="dataTableHeadingRow">
		<td class="dataTableHeadingContent" colspan="2"><b><?php echo TEXT_PRODUCT_SEARCH;?></b></td>
	</tr>
	<tr class="dataTableRow">
		<?php
			echo draw_form('product_search', FILENAME_ORDERS_EDIT, getMenuID('orders_edit'), 'get');
			echo draw_hidden_field('edit_action', 'products');
			echo draw_hidden_field('action', 'product_search');
			echo draw_hidden_field('oID', $_GET['oID']);
			echo draw_hidden_field('cID', $_POST['cID']);
		?>
		<td class="dataTableContent" width="40"><?php echo draw_input_field('search', '', 'size="30"');?></td>
		<td class="dataTableContent">
		<?php
			echo '<button type="submit" class="button" onclick="this.blur();">'.BUTTON_SEARCH.'</button>';
			echo '</td></form>';
		?>
	</tr>
</table>
<br /><br />
<?php
if ($_GET['action'] == 'product_search') {
	$products_data = $db->db_query("SELECT
										p.products_id,
										p.products_model,
										p.products_ean,
										pd.products_name,
										p.products_image,
										p.products_status
									FROM
										".TABLE_PRODUCTS." p,
										".TABLE_PRODUCTS_DESCRIPTION." pd
									WHERE
										p.products_id = pd.products_id
									AND 
										pd.language_id = '".$_SESSION['languages_id']."' 
									AND
										(pd.products_name like '%".$_GET['search']."%' OR p.products_model = '".$_GET['search']."' OR p.products_ean = '".$_GET['search']."') 
									ORDER BY 
										pd.products_name"); ?>
<table border="0" width="100%" cellspacing="0" cellpadding="2">
	<tr class="dataTableHeadingRow">
		<td class="dataTableHeadingContent"><b><?php echo TEXT_PRODUCT_ID;?></b></td>
		<td class="dataTableHeadingContent"><b><?php echo TEXT_QUANTITY;?></b></td>
		<td class="dataTableHeadingContent"><b><?php echo TEXT_PRODUCT;?></b></td>
		<td class="dataTableHeadingContent"><b><?php echo TEXT_PRODUCTS_MODEL;?></b></td>
		<td class="dataTableHeadingContent"><b>EAN</b></td>
		<td class="dataTableHeadingContent">&nbsp;</td>
	</tr>
	<?php while(!$products_data->EOF) { ?>
		<tr class="dataTableRow">
			<?php
				echo draw_form('product_ins', FILENAME_ORDERS_EDIT, 'action=product_ins&'.getMenuID('orders_edit'), 'post');
				echo draw_hidden_field('cID', $_POST['cID']);
				echo draw_hidden_field('oID', $_GET['oID']);
				echo draw_hidden_field('products_id', $products_data->fields['products_id']);
			?>
			<td class="dataTableContent"><?php echo $products_data->fields['products_id'];?></td>
			<td class="dataTableContent"><?php echo draw_input_field('products_quantity', $products_data->fields['products_quantity'], 'size="2"');?></td>
			<td class="dataTableContent"><?php echo $products_data->fields['products_name'];?></td>
			<td class="dataTableContent"><?php echo $products_data->fields['products_model'];?></td>
			<td class="dataTableContent"><?php echo $products_data->fields['products_ean'];?></td>
			<td class="dataTableContent">
			<?php
				echo '<button type="submit" class="button" onclick="this.blur();">'.BUTTON_INSERT.'</button>';
				echo '</form>';
			?>
			</td>
		</tr>
	<?php 
		$products_data->MoveNext();
	} ?>
</table>
<?php } ?>
<br /><br />